/*
 * Copyright 2012 Fabian Wenzelmann
 * 
 * This file is part of Recognition-Procedures-for-Boolean-Functions.
 * 
 * Recognition-Procedures-for-Boolean-Functions is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Recognition-Procedures-for-Boolean-Functions is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Recognition-Procedures-for-Boolean-Functions.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.wenzelmf.booleanFunction.booleanExpression;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * Boolean expression that represents the constant <i>true</i>.
 * 
 * @author Fabian Wenzelmann
 * @version 1.0
 *
 */
public class True extends BooleanExpression
{

	/**
	 * String for the string representation of <i>true</i>.
	 */
	public static final String TRUE_STRING = "true";
	
	/**
	 * A constant field for a True object.
	 */
	public static final True TRUE = new True();
	
	/**
	 * Creates a new True object.
	 */
	public True()
	{
		;
	}
	
	@Override
	public boolean getTruthValue(Assignment alpha)
	{
		return true;
	}
	
	@Override
	public String toString()
	{
		return TRUE_STRING;
	}
	
	/**
	 * Returns the hash code of the string representation.
	 */
	@Override
	public int hashCode()
	{
		return TRUE_STRING.hashCode();
	}
	
	/**
	 * Returns <code>true</code> if <code>other</code> is also a True object.
	 */
	@Override
	public boolean equals(Object other)
	{
		return (other != null) && (other instanceof True);
	}

	@Override
	public BooleanFunction getFunction()
	{
		return new BooleanFunction()
		{

			@Override
			public boolean getValue(Iterator<Boolean> inputPoint)
			{
				return true;
			}

			@Override
			public int getDimension()
			{
				return 0;
			}
			
		};
	}

	@Override
	public int getArity()
	{
		return 0;
	}
	
	@Override
	public Iterator<BooleanExpression> iterator()
	{
		return new Iterator<BooleanExpression>()
				{

					@Override
					public boolean hasNext()
					{
						return false;
					}

					@Override
					public BooleanExpression next()
					{
						throw new NoSuchElementException("True expression does not have subformulae.");
					}

					@Override
					public void remove()
					{
						throw new UnsupportedOperationException("It is not allowed to remove elements from a formula.");
					}
				};
	}
	
	@Override
	public int completeSize()
	{
		return 1;
	}
	
}
